package com.fin.quant.common;

import java.time.LocalTime;

public class TradeUtil {

    // 上午交易时段
    private static LocalTime morningStart = LocalTime.of(9, 30);
    private static LocalTime morningEnd = LocalTime.of(11, 30);

    // 下午交易时段
    private static LocalTime afternoonStart = LocalTime.of(13, 0);
    private static LocalTime afternoonEnd = LocalTime.of(15, 0);

    // 判断某个时间是否在[start, end]区间内
    public static boolean isWithin(LocalTime time, LocalTime start, LocalTime end) {
        return !time.isBefore(start) && !time.isAfter(end);
    }

    public static boolean isTradingTime() {
        // 当前时间
        LocalTime now = LocalTime.now();
        if (isWithin(now, morningStart, morningEnd)) {
            return true;
        } else if (isWithin(now, afternoonStart, afternoonEnd)) {
            return true;
        } else {
            return false;
        }
    }
}
